package com.baymax.test.scene.demo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.baymax.test.scene.BaseGroupScene
import com.baymax.test.scene.Player
import com.baymax.test.scene.addButton
import com.baymax.test.scene.addDFView
import com.baymax.test.scene.newSceneFlexContainer
import com.bytedance.scene.ktx.replace

class PlayerCaseScene : BaseGroupScene() {
    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): ViewGroup {
        return p1.newSceneFlexContainer {
            val genId = View.generateViewId()
            addButton("test s1") {
                replace(genId, SeekCase(), genId.toString())
            }

            addButton("test 2s") {
                replace(genId, PlayerChange(), genId.toString())
            }
            addDFView(-1, -1, FrameLayout(context).apply { id = genId })

        }
    }

    class PlayerChange() : BaseGroupScene() {

        private val url1 =
            "http://183.207.249.71:80/cntv/live1/H265-5500k-1080P-cctv11/H265-5500k-1080P-cctv11?OTTUserToken=53402000838-74:97:81:ee:0e:29&UserName=53402000838&MAC=74:97:81:ee:0e:29&stbID=65100499007035100000749781EE0E29&accountinfo=P05T3wzU16dLVehoiA1GzLlia%2FfWW9WAMUJeaBm9Sq9cKHHEgB%2FbFvZ7xI07hR44a4tp%2FA%2FyTHWKkaoYZeCNOHUSbriiYuymiljKqDiJh1oi1gOcY%2FfA6O5avKUmdg%2FVWZCSssd0hXfVwXqLGGB0Ww%3D%3D%3A20231030191344%2C53402000838%2C221.131.123.204%2C20231030191344%2CH265-5500k-1080P-cctv11%2CD29F927EE42590EEE1D4226FDFC45D1D%2C%2C0%2C1%2C-1%2C%2C2%2C%2C-1%2C-3%2C2%2CEND&GuardEncType=2"
        private val url2 =
            "http://183.207.249.71:80/jsyd/live1/G_CCTV-2-MD/G_CCTV-2-MD?OTTUserToken=53402000838-74:97:81:ee:0e:29&UserName=53402000838&MAC=74:97:81:ee:0e:29&stbID=65100499007035100000749781EE0E29&accountinfo=P05T3wzU16dLVehoiA1GzLlia%2FfWW9WAMUJeaBm9Sq9cKHHEgB%2FbFvZ7xI07hR44a4tp%2FA%2FyTHWKkaoYZeCNOHUSbriiYuymiljKqDiJh1q3BWrdgdKC7V%2FGLEUVL%2FTMCY2%2BrVZhFVZaPeCXI2ChDA%3D%3D%3A20231030185938%2C53402000838%2C221.131.123.204%2C20231030185938%2CG_CCTV-2-MD%2CD29F927EE42590EEE1D4226FDFC45D1D%2C%2C0%2C1%2C-1%2C%2C2%2C%2C-1%2C-3%2C2%2CEND&GuardEncType=2"
        private val player by lazy {
            Player(requireSceneContext())
        }


        fun start1() = player.start(url1, 0)
        fun start2() = player.start(url2, 0)


        override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): ViewGroup =
            p1.newSceneFlexContainer {
                addDFView(300, 300, player)
                addButton("play 1") {
                    start1()
                }
                addButton("play 2") {
                    start2()
                }
            }
    }


    class SeekCase() : BaseGroupScene() {
        private val url =
            "http://cdnrrs.gx.chinamobile.com/77777777/16/20190905/268488169/268488169.ts"
        private val player by lazy {
            Player(requireSceneContext()).apply {
            }

        }


        fun start(pos: Int = 0) = player.start(url, pos)
        fun stop() = kotlin.run {
            player.stop()
        }

        fun triggerCover() {
            if (player.cover.visibility == View.VISIBLE) {
                player.cover.visibility = View.GONE
            } else {
                player.cover.visibility = View.VISIBLE
            }
        }

        override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): ViewGroup =
            p1.newSceneFlexContainer {
                addDFView(300, 300, player)
                addButton("start ") {
                    start()
                }
                addButton("start at 120s") {
                    start(120000)
                }

                addButton("end 1") {
                    stop()
                }

                addButton("triggerCover") {
                    triggerCover()
                }

            }
    }


}